package com.vint.leetcode;

public class Leetcode605 {
	public boolean canPlaceFlowers(int[] flowerbed, int n) {
		int sum = 0;
		int zero = 0;
		for (int i = 0; i < flowerbed.length; i++) {
			if(i==0){
				zero++;
			}
			if (flowerbed[i] == 1) {
				int flower = (zero - 1) / 2;
				sum += flower;
				zero = 0;
			} else {
				zero++;
				if (i == flowerbed.length - 1) {
					sum += zero / 2;
				}
			}
		}
		return sum >= n;
	}
}
